Skip to content

feat(go): let callers set Prometheus histogram buckets - #286

Merged
lan17 merged 1 commit into
mainfrom
feat/go-prometheus-buckets
Nov 17, 2026
Merged

lan17 merged 1 commit into
mainfrom
feat/go-prometheus-buckets

Conversation

@lan17

@lan17 lan17 commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Problem

Each Go Prometheus timer histogram exports 15 series per label set: 12 fixed boundaries, +Inf, _sum and _count. A backend that bills each bucket series, such as Datadog, charges for all of them, and a caller cannot change the boundaries. The maintainer reported this while he onboarded a Go service that exports through its own registry. In that service a remote get takes about 2 ms, the read budget is 50 ms and the write budget is 250 ms, so the get buckets above 50 ms are almost always empty. Refs #285 for the TypeScript and Rust adapters.

Change

Public API, Go only. PrometheusBuckets(kind, bounds) returns a PrometheusOption that replaces the finite boundaries of one histogram. kind is the existing PrometheusCollectorSchema.Kind, such as get, fallback, serialization or compressionDuration.

timer := []float64{0.001, 0.0025, 0.005, 0.01, 0.025, 0.05, 0.25} // example boundaries only
metrics, err := dialcache.NewPrometheusMetrics(registry, "",
	dialcache.PrometheusBuckets("get", timer),
	dialcache.PrometheusBuckets("fallback", timer))
  • NewPrometheusMetrics, NewPrometheusMetricsWithBindings and PrometheusCollectorSchemas take the options as a final variadic parameter. Existing calls compile unchanged. Only code that stores one of these functions in a variable of the old function type must change.
  • Reuse of an earlier DialCache group and explicit bindings compare the schema that the options build. A default adapter does not reuse a group that has custom buckets, and a binding with custom buckets needs the same option.
  • Construction fails before it registers anything for an unknown or counter kind, a repeated kind, and boundaries that are empty, not finite or not strictly increasing. The adapter copies the caller's slice, because client_golang keeps the slice it receives.
  • With no options, every schema still matches the TypeScript adapter. TestPrometheusWireSchemaMatchesTypeScriptBinding is unchanged.
  • No design record. The change is additive, leaves cache behavior and cache construction unchanged, and adds no option other than buckets. The maintainer chose a Go-only option with the current defaults. Issue Decouple core observability from Prometheus #53 already allowed bucket options as adapter-owned configuration. No docs/upgrading.md note, because nothing changes for existing callers.
  • Docs: the shared bucket table in docs/observability.md now says that the boundaries are the defaults, and a Go note shows the option with example boundaries. go/README.md and formal/guides/GO-PARITY.md name the option.
  • Ledgers: source-audit.json for the three edited pages, feature-coverage.json for go/metrics_test.go plus the new TestPrometheusBucketOptions evidence under X01.prometheus-schema, and go-parity.json for go/metrics_prometheus.go with the two new symbols and the mapping rationale. They were refreshed in the order of formal/catalogs/README.md.

Ports

Port Status
TypeScript N/A: no bucket option yet, defaults unchanged; #285
Go done
Rust N/A: no bucket option yet, defaults unchanged; #285
Python N/A: ships no Prometheus exporter

Validation

Head: 601add9

  • make check-go (go vet, gofmt and race tests with coverage) at 601add9: passed.
  • go -C go test -race -count=1 -run Prometheus ./ at 601add9: passed, 5 tests including the new TestPrometheusBucketOptions.
  • make audit at 601add9: passed.
  • corepack pnpm docs:check and make docs at 601add9: passed.
  • PR CI at 601add9: every check passed, including test, go, typescript, rust, python, wire, quint, differential (1) to (4), Build documentation and Validate PR title.
  • formal-full.yaml in replay mode, run 44025119619, at 601add9: success (symbolic, generate, and TypeScript, Go, Rust and Python parity).

Not run: the mutation lanes, because the mutant rule does not fire (no catalog entry names a changed file). Locally, make integration-go and make integration-wire need Docker. check-ts, check-rust and check-python were not run locally, because those ports are unchanged. CI ran all of them.

Follow-ups

PrometheusBuckets(kind, bounds) replaces the bucket boundaries of one
Prometheus histogram, keyed by PrometheusCollectorSchema.Kind.
NewPrometheusMetrics, NewPrometheusMetricsWithBindings and
PrometheusCollectorSchemas accept the options, so reuse and bindings
compare the schema the options build. Construction rejects an unknown or
counter kind, a repeated kind, and bounds that are empty, not finite or
not increasing. Without options every schema still matches TypeScript.
@codecov-commenter

codecov-commenter commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.79%. Comparing base (135090e) to head (601add9).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #286      +/-   ##
==========================================
+ Coverage   94.77%   94.79%   +0.01%     
==========================================
  Files          84       84              
  Lines       13178    13199      +21     
  Branches      805      805              
==========================================
+ Hits        12490    12512      +22     
+ Misses        622      621       -1     
  Partials       66       66              
Flag Coverage Δ
go 94.02% <100.00%> (+0.09%) ⬆️
python 93.60% <ø> (ø)
rust 94.78% <ø> (ø)
typescript 97.21% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lan17
lan17 marked this pull request as ready for review November 17, 2026 08:40
@lan17
lan17 merged commit 995c629 into main Nov 17, 2026
37 checks passed
@lan17
lan17 deleted the feat/go-prometheus-buckets branch November 17, 2026 08:40
lan17 added a commit that referenced this pull request Nov 17, 2026
Resolve the ledger conflicts with the Prometheus bucket option (#286):
take main's source-audit.json and go-parity.json, apply the expected
error mapping again, and refresh both in the catalog README's order.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants